/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
//package oop.demo.restaurantmanagementsystem;
package top.anka1.ims.RestaurantManagementSystem;
import java.util.ArrayList;
/**
 * Meal class for managing meals composed of ingredients
 * name: the meals name
 * Ingredients: list of ingrdients
 * @author ashongtical
 * @author Anka
 */

public class Meal implements Priceable {
    private String name;
    private ArrayList<Ingredient> ingredients;
    private String ingredientsString = "";
    private Double totalPrice = 0.0;

    //Constructor to initialize the meal
    public Meal(String name) {
        this.name = name;
        this.ingredients = new ArrayList<>();
    }
    //Get the name of the meal
    public String getName() {
        return name;
    }
    //Add an ingredient to the meal
    public void addIngredient(Ingredient ingredient) {
        ingredients.add(ingredient);
        if (ingredientsString.isEmpty()) {
            ingredientsString = ingredient.getName();
        } else {
            ingredientsString += ", " + ingredient.getName();
        }
        totalPrice += ingredient.getPrice();
    }
    //Get the ingredients of the meal
    public ArrayList<Ingredient> getIngredients() {
        return ingredients;
    }
    public String getIngredientsString() {
        return ingredientsString;
    }
    public Double getTotalPrice() {
        return totalPrice;
    }
    //Get the price of the meal
    @Override
    public double getPrice() {
        double totalPrice = 0;
        for (Ingredient ingredient : ingredients) {
            totalPrice += ingredient.getPrice();
        }
        return totalPrice;
    }
    //Get the string representation of the meal
    @Override
    public String toString() {
        String ingredientsString = name + " - RMB" + String.format("%.2f", getPrice()) + "\n" + "  Ingredients: ";
        for (int i = 0; i < ingredients.size(); i++) {
            if (i == ingredients.size() - 1) {
                ingredientsString += ingredients.get(i).getName();
            } else {
                ingredientsString += ingredients.get(i).getName() + ", ";
            }
        }
        return ingredientsString;
    }
}
